<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hero项目登录演示</title>
    
    <!-- 引入样式 -->
    <link rel="stylesheet" href="css/login-modal.css">
    
    <style>
        /* 页面基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
        }
        
        .header h1 {
            color: #667eea;
            margin-bottom: 15px;
            font-size: 2.5em;
            font-weight: 600;
        }
        
        .header p {
            color: #666;
            font-size: 1.1em;
        }
        
        .demo-section {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
        }
        
        .demo-section h2 {
            color: #333;
            margin-bottom: 20px;
            font-size: 1.8em;
        }
        
        .button-group {
            display: flex;
            gap: 15px;
            flex-wrap: wrap;
            margin-bottom: 25px;
        }
        
        .demo-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
        }
        
        .demo-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        .demo-btn.secondary {
            background: #6b7280;
        }
        
        .demo-btn.danger {
            background: #ef4444;
        }
        
        .status-panel {
            background: #f8fafc;
            border: 2px solid #e5e7eb;
            border-radius: 10px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .status-panel h3 {
            margin-bottom: 15px;
            color: #374151;
        }
        
        .status-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid #e5e7eb;
        }
        
        .status-item:last-child {
            border-bottom: none;
        }
        
        .status-label {
            font-weight: 500;
            color: #6b7280;
        }
        
        .status-value {
            color: #374151;
            font-family: monospace;
        }
        
        .status-value.success {
            color: #059669;
        }
        
        .status-value.error {
            color: #dc2626;
        }
        
        .log-panel {
            background: #1f2937;
            color: #e5e7eb;
            border-radius: 10px;
            padding: 20px;
            margin-top: 20px;
            max-height: 300px;
            overflow-y: auto;
            font-family: monospace;
            font-size: 14px;
        }
        
        .log-item {
            margin-bottom: 5px;
            padding: 5px 0;
            border-bottom: 1px solid #374151;
        }
        
        .log-time {
            color: #9ca3af;
        }
        
        .log-type-info {
            color: #60a5fa;
        }
        
        .log-type-success {
            color: #34d399;
        }
        
        .log-type-error {
            color: #f87171;
        }
        
        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }
            
            .header, .demo-section {
                padding: 20px;
            }
            
            .header h1 {
                font-size: 2em;
            }
            
            .button-group {
                flex-direction: column;
            }
            
            .demo-btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 页面头部 -->
        <div class="header">
            <h1>Hero项目登录系统演示</h1>
            <p>这是一个完整的登录注册系统演示页面，支持模态框登录、状态管理和登录过期检测。</p>
        </div>
        
        <!-- 模态框演示 -->
        <div class="demo-section">
            <h2>📱 模态框演示</h2>
            <div class="button-group">
                <button class="demo-btn" onclick="HeroLoginModal.showLogin()">显示登录模态框</button>
                <button class="demo-btn secondary" onclick="HeroLoginModal.showRegister()">显示注册模态框</button>
                <button class="demo-btn danger" onclick="HeroLoginModal.showLogoutConfirm()">显示注销确认</button>
                <button class="demo-btn secondary" onclick="HeroLoginModal.showExpiredModal()">显示登录过期提示</button>
            </div>
        </div>
        
        <!-- 快速操作 -->
        <div class="demo-section">
            <h2>⚡ 快速操作</h2>
            <div class="button-group">
                <button class="demo-btn" onclick="quickLogin()">快速登录 (admin/123456)</button>
                <button class="demo-btn secondary" onclick="checkLoginStatus()">检查登录状态</button>
                <button class="demo-btn secondary" onclick="getUserInfo()">获取用户信息</button>
                <button class="demo-btn danger" onclick="quickLogout()">快速注销</button>
            </div>
        </div>
        
        <!-- 跳转测试 -->
        <div class="demo-section">
            <h2>🚀 页面跳转测试</h2>
            <div class="button-group">
                <button class="demo-btn secondary" onclick="testOpenAdmin()">新窗口打开管理后台</button>
                <button class="demo-btn secondary" onclick="testNotification()">测试通知功能</button>
            </div>
        </div>
        
        <!-- 状态面板 -->
        <div class="demo-section">
            <h2>📊 系统状态</h2>
            <div class="status-panel">
                <h3>当前状态</h3>
                <div class="status-item">
                    <span class="status-label">登录状态:</span>
                    <span class="status-value" id="login-status">检查中...</span>
                </div>
                <div class="status-item">
                    <span class="status-label">Token:</span>
                    <span class="status-value" id="token-status">无</span>
                </div>
                <div class="status-item">
                    <span class="status-label">用户名:</span>
                    <span class="status-value" id="username-status">未登录</span>
                </div>
                <div class="status-item">
                    <span class="status-label">最后操作:</span>
                    <span class="status-value" id="last-action">页面加载</span>
                </div>
            </div>
        </div>
        
        <!-- 操作日志 -->
        <div class="demo-section">
            <h2>📋 操作日志</h2>
            <div class="log-panel" id="log-panel">
                <!-- 日志内容将在这里显示 -->
            </div>
            <div style="margin-top: 15px;">
                <button class="demo-btn secondary" onclick="clearLog()">清空日志</button>
            </div>
        </div>
    </div>
    
    <!-- 引入脚本 -->
    <script src="js/auth.js"></script>
    <script src="js/login-modal.js"></script>
    <script src="js/common.js"></script>
    
    <script>
        // 日志管理
        class Logger {
            static log(message, type = 'info') {
                const now = new Date();
                const time = now.toLocaleTimeString();
                const logPanel = document.getElementById('log-panel');
                
                const logItem = document.createElement('div');
                logItem.className = 'log-item';
                logItem.innerHTML = `
                    <span class="log-time">[${time}]</span>
                    <span class="log-type-${type}">[${type.toUpperCase()}]</span>
                    ${message}
                `;
                
                logPanel.insertBefore(logItem, logPanel.firstChild);
                
                // 限制日志条数
                if (logPanel.children.length > 50) {
                    logPanel.removeChild(logPanel.lastChild);
                }
            }
            
            static clear() {
                document.getElementById('log-panel').innerHTML = '';
            }
        }
        
        // 状态更新
        function updateStatus() {
            const isLoggedIn = HeroAuth.isLoggedIn();
            const token = HeroAuth.getToken();
            
            document.getElementById('login-status').textContent = isLoggedIn ? '已登录' : '未登录';
            document.getElementById('login-status').className = `status-value ${isLoggedIn ? 'success' : 'error'}`;
            
            document.getElementById('token-status').textContent = token ? 
                token.substring(0, 20) + '...' : '无';
            
            if (isLoggedIn) {
                HeroAuth.getInfo()
                    .then(data => {
                        if (data && data.user) {
                            document.getElementById('username-status').textContent = data.user.userName || '未知用户';
                        }
                    })
                    .catch(error => {
                        document.getElementById('username-status').textContent = '获取失败';
                        Logger.log(`获取用户信息失败: ${error.message}`, 'error');
                    });
            } else {
                document.getElementById('username-status').textContent = '未登录';
            }
            
            document.getElementById('last-action').textContent = new Date().toLocaleTimeString();
        }
        
        // 快速登录
        function quickLogin() {
            Logger.log('开始快速登录...', 'info');
            HeroAuth.login('admin', '123456')
                .then(data => {
                    Logger.log('登录成功!', 'success');
                    updateStatus();
                })
                .catch(error => {
                    Logger.log(`登录失败: ${error.message}`, 'error');
                    updateStatus();
                });
        }
        
        // 检查登录状态
        function checkLoginStatus() {
            Logger.log('检查登录状态...', 'info');
            const isLoggedIn = HeroAuth.isLoggedIn();
            Logger.log(`登录状态: ${isLoggedIn ? '已登录' : '未登录'}`, isLoggedIn ? 'success' : 'error');
            
            if (isLoggedIn) {
                HeroAuth.validateToken()
                    .then(() => {
                        Logger.log('Token验证成功', 'success');
                    })
                    .catch(error => {
                        Logger.log(`Token验证失败: ${error.message}`, 'error');
                    });
            }
            updateStatus();
        }
        
        // 获取用户信息
        function getUserInfo() {
            Logger.log('获取用户信息...', 'info');
            HeroAuth.getInfo()
                .then(data => {
                    Logger.log(`用户信息获取成功: ${JSON.stringify(data, null, 2)}`, 'success');
                    updateStatus();
                })
                .catch(error => {
                    Logger.log(`获取用户信息失败: ${error.message}`, 'error');
                    updateStatus();
                });
        }
        
        // 快速注销
        function quickLogout() {
            Logger.log('开始注销...', 'info');
            HeroAuth.logout()
                .then(() => {
                    Logger.log('注销成功!', 'success');
                    updateStatus();
                })
                .catch(error => {
                    Logger.log(`注销失败: ${error.message}`, 'error');
                    updateStatus();
                });
        }
        
        // 清空日志
        function clearLog() {
            Logger.clear();
            Logger.log('日志已清空', 'info');
        }
        
        // 测试新窗口打开管理后台
        function testOpenAdmin() {
            Logger.log('测试新窗口打开管理后台...', 'info');
            HeroCommon.openAdmin();
        }
        
        // 测试通知功能
        function testNotification() {
            Logger.log('测试通知功能...', 'info');
            HeroCommon.showNotification('这是一个成功消息!', 'success');
            
            setTimeout(() => {
                HeroCommon.showNotification('这是一个警告消息!', 'warning');
            }, 1000);
            
            setTimeout(() => {
                HeroCommon.showNotification('这是一个错误消息!', 'error');
            }, 2000);
            
            setTimeout(() => {
                HeroCommon.showNotification('这是一个信息消息!', 'info');
            }, 3000);
        }
        
        // 设置登录成功回调
        HeroLoginModal.setLoginSuccessCallback((data) => {
            Logger.log('模态框登录成功!', 'success');
            updateStatus();
        });
        
        // 设置注销成功回调
        HeroLoginModal.setLogoutSuccessCallback(() => {
            Logger.log('模态框注销成功!', 'success');
            updateStatus();
        });
        
        // 监听自定义事件
        document.addEventListener('hero:loginSuccess', (e) => {
            Logger.log(`登录成功事件触发: ${JSON.stringify(e.detail)}`, 'success');
        });
        
        document.addEventListener('hero:logoutSuccess', (e) => {
            Logger.log('注销成功事件触发', 'success');
        });
        
        document.addEventListener('hero:commonReady', (e) => {
            Logger.log('HeroCommon工具库已就绪', 'info');
        });
        
        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            Logger.log('页面加载完成，初始化演示系统...', 'info');
            updateStatus();
            
            // 每30秒检查一次登录状态
            setInterval(() => {
                if (HeroAuth.isLoggedIn()) {
                    HeroAuth.validateToken().catch(error => {
                        Logger.log(`定时Token验证失败: ${error.message}`, 'error');
                        updateStatus();
                    });
                }
            }, 30000);
        });
        
        // 定期更新状态显示
        setInterval(updateStatus, 5000);
    </script>
</body>
</html>